from coin.exchange.huobi_futures.kr_rest.futures_product import (HuobiFuturesProduct)
from coin.exchange.okex_futures.kr_rest.futures_product import (OkexFuturesProduct)


def adjust_product_expiry(product, current_datetime):
  if isinstance(product, (OkexFuturesProduct, HuobiFuturesProduct)):
    product = product.FromCurrencyPair2AndContractType(product.base,
                                                       product.quote,
                                                       product.contract_type,
                                                       current_datetime)
  return product


def get_post_only(market_type, exchange):
  post_only_pool = [
      ('Margin', 'Bitfinex'),
      ('Spot', 'Binance'),
      ('Spot', 'Bitfinex'),
      ('Spot', 'Hitbtc'),
      ('Spot', 'Huobi'),
      ('Spot', 'Okex'),
  ]
  return (market_type, exchange) in post_only_pool


def get_execution_delay():
  return [0.25]


def get_machine_by_subreq(subreq):
  if subreq.exchange == 'Okex':
    # cn aliyun doesn't have bitflyer feed
    return 'feed-01.ap-northeast-1.aws'
    # return 'feed-01.cn-hongkong.aliyun'
  elif subreq.exchange in ('Binance', 'Huobi', 'Bitflyer', 'Bithumb', 'Upbit'):
    return 'feed-01.ap-northeast-1.aws'
  elif subreq.exchange == 'Bitmex':
    return 'feed-01.eu-west-1.aws'
  else:
    raise ValueError(subreq)
